import logo from '../assets/img/logo.svg';
import '../assets/css/App.css';

import { useEffect } from 'react';
import { useState } from 'react';
import { getLocalData } from '../utils';
import { login, getProfile, getPersonalFM } from '../service/app';


function App() {

  useEffect(() => {
    getProfile()
    getPersonalFM()
    return () => {
    }
  }, [])

  const isLogin = getLocalData('ck')
  const profile = getLocalData('profile')?.profile


  return (
    <div className="App">
      <header className="App-header">
        <img style={{
          borderRadius: '50%',
        }} src={profile ? profile.avatarUrl : logo} className="App-logo" alt="logo" />
        <p style={{
          marginTop: '48px'
        }}>
          {profile?.nickname}
        </p>
        <a
          className="App-link"
          href="https://reactjs.org"
          target="_blank"
          rel="noopener noreferrer"
        >
          {profile?.signature}
        </a>

        {!isLogin && <Login />}
      </header>
    </div>
  );
}

const Login = () => {

  const [name, setName] = useState("")
  const [pwd, setPwd] = useState("")
  return (
    <>
      <div>
        <input type="text" onChange={e => {
          setName(e.target.value)
        }} />
        <input type="password" onChange={e => {
          setPwd(e.target.value)
        }} />
        <button type="submit" onClick={() => {
          login('phone', {
            phone: name,
            password: pwd
          })
        }}>login</button>
      </div>
    </>
  )


}

export default App;
